// pages/task-detail/index.js
Page({
  data: {
    activeNames: ['1'],
    cargoPickUpPictureList: [],
    cargoPictureList: [],
    jobId: ''
  },
  async onLoad(e) {
    console.log(e.id);
    this.data.jobId = e.id
    const res = await wx.$http.get('/driver/tasks/details/' + this.data.jobId)
    console.log(res);
  },
  onChange(event) {
    this.setData({ activeNames: event.detail });
  },

  //   回退
  goBack() {
      console.log('h');
      wx.switchTab({
          url: '/pages/task/task',
      })
  },
  // 上传图片
  afterRead(e) {
    console.log(e.detail.file);
    const { file } = e.detail;
    wx.uploadFile({
      url: wx.$http.baseURL + '/driver/files/upload', // 仅为示例，非真实的接口地址
      filePath: file.url,
      name: 'file',
      header: {
        Authorization:  getApp().getToken(),
      },
      success: (res) => {
        console.log(res);
        console.log(res.data);
        const data = JSON.parse(res.data)
        console.log(data.data);
        const { cargoPickUpPictureList }  = this.data
        cargoPickUpPictureList.push({...file, url: data.data})
        this.setData({ cargoPickUpPictureList })
      }
    }); 
  },
    // 上传图片 很蠢的做法
    afterReadTwo(e) {
      console.log(e.detail.file);
      const { file } = e.detail;
      wx.uploadFile({
        url: wx.$http.baseURL + '/driver/files/upload', // 仅为示例，非真实的接口地址
        filePath: file.url,
        name: 'file',
        header: {
          Authorization:  getApp().getToken(),
        },
        success: (res) => {
          console.log(res);
          console.log(res.data);
          const data = JSON.parse(res.data)
          console.log(data.data);
          const { cargoPictureList }  = this.data
          cargoPictureList.push({...file, url: data.data})
          this.setData({ cargoPictureList })
        }
      }); 
    } 
}) 
